# 交叉曲线的颜色填充
import matplotlib.pyplot as plt
import numpy as np

# np.linspace创建等差数列
x = np.linspace(0, 3, 500)
y1 = np.sin(2*np.pi*x)
y2 = 1.1*np.sin(3*np.pi*x)

# 获得一个画布对象fig和一个坐标轴列表ax
# 这是一个三行一列的共享x轴的网格布局子区
fig, ax = plt.subplots(4, 1, sharex="all")

# between y2 and 0
ax[0].fill_between(x, 0, y2, alpha=0.5)
ax[0].set_ylim(-1.2, 1.2)

# between y2 and 1.1
ax[1].fill_between(x, y2, 1.1, alpha=0.5)
ax[1].set_ylim(-1.2, 1.2)

# between y1 and y2
ax[2].fill_between(x, y1, y2, alpha=0.5)
ax[2].set_xlim(0, 3)
ax[2].set_ylim(-1.2, 1.2)

plt.show()